<?php

namespace App\models;

use Illuminate\Database\Eloquent\Model;

class Warehouse extends Model
{
    protected $table = 'warehouse';
    protected $primaryKey = 'warehouse_id';
    public $timestamps = false; //关闭模型自动维护时间戳

    //查询添加的仓库是否存在
    public static function selectone($data)
    {
        return Warehouse::where('warehouse_name',$data['warehouse_name'])
                        ->where('warehouse_provincial',$data['warehouse_provincial'])
                        ->where('warehouse_city',$data['warehouse_city'])
                        ->where('warehouse_district',$data['warehouse_district'])
                        ->where('warehouse_address',$data['warehouse_address'])
                        ->get()
                        ->toArray();
    }

    //添加仓库
    public static function adds($data)
    {
        $time=date('Y-m-d');
        $ware=new Warehouse();
        $ware->warehouse_name=$data['warehouse_name'];
        $ware->warehouse_provincial=$data['warehouse_provincial'];
        $ware->warehouse_city=$data['warehouse_city'];
        $ware->warehouse_district=$data['warehouse_district'];
        $ware->warehouse_address=$data['warehouse_address'];
        $ware->warehouse_status=$data['warehouse_status'];
        $ware->warehouse_service_region=$data['warehouse_service_region'];
        $ware->warehouse_time=$time;
        return $ware->save();
    }

    //查询所有仓库信息
    public static function select()
    {
        return self::all()->toArray();
    }
    
    //删除仓库
    public static function dels($id)
    {
        return self::destroy($id);
    }

    //查询修改仓库
    public static function saves($id)
    {
        return self::find($id);
    }

    //执行修改仓库数据
    public static function dosave($data)
    {
        $time=date('Y-m-d');
        $ware=self::find($data['warehouse_id']);
        $ware->warehouse_name=$data['warehouse_name'];
        $ware->warehouse_provincial=$data['warehouse_provincial'];
        $ware->warehouse_city=$data['warehouse_city'];
        $ware->warehouse_district=$data['warehouse_district'];
        $ware->warehouse_address=$data['warehouse_address'];
        $ware->warehouse_status=$data['warehouse_status'];
        $ware->warehouse_service_region=$data['warehouse_service_region'];
        $ware->warehouse_time=$time;
        return $ware->save();
    }
}
